{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <div class="form-group">
                    <input type="hidden" id="id" value="{$data.id}">
                    <label for="name">商品名称</label>
                    <input type="text" class="form-control" id="name" value="{$data.name}"
                        placeholder="请输入商品名称">
                </div>
                <div class="form-group file-group">
                    <label for="subimages">商品图片</label>
                    <div class="input-group">
                        <input type="text" id="subimages" class="form-control file-value" name="subimages"
                            value="{$data.subimages}" placeholder="商品图片">
                        <input type="file" accaccept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none">
                        <div class="input-group-btn">
                            <button class="btn btn-default file-browser" type="button">上传图片</button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="type">商品类型</label>
                    <select id="type" class="form-control">
                        <option value="0" {if $data["type"]==0}selected{/if}>兑换会员</option>
                        <option value="1" {if $data["type"]==1}selected{/if}>其他类型</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="detail">商品描述</label>
                    <textarea class="form-control" id="detail" rows="3"
                        placeholder="商品描述">{$data["detail"]}</textarea>
                </div>
                <div class="form-group">
                    <label for="price">消耗金币数/支付宝支付时填写金额</label>
                    <input type="number" class="form-control" id="price" value="{$data.price}" placeholder="请输入消耗金币数">
                </div>
                <div class="form-group">
                    <label for="content">会员天数(其他类型填写json格式)</label>
                    <input type="text" class="form-control" id="content" value="{$data.content}"
                        placeholder="请输入会员天数(其他类型填写json格式)">
                </div>
                <div class="form-group">
                    <label for="stock">库存数量</label>
                    <input type="number" class="form-control" id="stock" value="{$data.stock}"
                        placeholder="请输入库存数量">
                </div>
                <div class="form-group">
                    <label for="appid">appid</label>
                    <select class="form-control" id="appid" disabled>
                        <option value="" disabled>请选择app</option>
                        {foreach :query('app') as $key=>$value }
                        <option value="{$value['appid']}" {if $data["appid"]==$value["appid"]}selected{/if}>
                            {$value["appname"]}(appid:{$value['appid']})</option>
                        {/foreach}
                    </select>
                </div>
                <div class="form-group">
                    <label for="payment">支付类型</label>
                    <select class="form-control" id="payment">
                        <option value="" disabled>请选择支付类型</option>
                        <option value="0" {if $data["payment"]==0}selected{/if}>支付宝支付</option>
                        <option value="1" {if $data["payment"]==1}selected{/if}>金币支付</option>
                        <option value="2" {if $data["payment"]==2}selected{/if}>积分支付</option>
                        <option value="3" {if $data["payment"]==3}selected{/if}>源支付</option>
                        <option value="4" {if $data["payment"]==4}selected{/if}>易支付</option>
                    </select>
                </div>
                <button type="buttons" onclick="updateshop()" class="btn btn-w-sm btn-primary mb-2">提交</button>
                <button type="button" class="btn btn-default mb-2" onclick="javascript:history.back(-1);return false;">返
                    回
                </button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    function changenone(obj) {
        if (obj.options[obj.selectedIndex].value == 1) {
            document.getElementById("select_else").style.display = "";
        } else {
            document.getElementById("select_else").style.display = "none";
        }
    }

    function updateshop() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var id = $.trim($("#id").val());
        var name = $.trim($("#name").val());
        var subimages = $.trim($("#subimages").val());
        var type = $.trim($("#type").val());
        var detail = $.trim($("#detail").val());
        var price = $.trim($("#price").val());
        var content = $.trim($("#content").val());
        var stock = $.trim($("#stock").val());
        var appid = $.trim($("#appid").val());
        var payment = $.trim($("#payment").val());
        $.ajax({
            type: "POST",
            url: "{:url('shop/edit')}",
            data: {
                id: id,
                name: name,
                subimages: subimages,
                type: type,
                detail: detail,
                price: price,
                content: content,
                stock: stock,
                appid: appid,
                payment: payment
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }

</script>
{/block}